﻿@{
    ViewBag.Title = "RepairIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var _organizeid = "", _State = "", _DeviceId = "";
    $(function () {
        InitialPage();
        GetTree1();
        GetTree2();
        GetGrid();
    }
     );
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);
            }, 200);
            e.stopPropagation();
        });
        $("#OrganizeId").ComboBoxTree({
            // url: "../../ResourceManage/CS_DeviceRepair/GetOrganizeTree",
            url: "../../BaseManage/Organize/GetTreeJson",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    $('#btn_Search').trigger("click");
                }
            },
            description: "===选择组织机构==="
        });
        $("#OrganizeId").ComboBoxTreeSetValue(_organizeid);

        $("#RepairWay").ComboBox({
            //  url: " ",
            data: [{ "key": "1", "value": "测试方式1" }, { "key": "2", "value": "测试方式2" }, { "key": "3", "value": "测试方式3" }],
            id: "key",
            text: "value",
            description: "==请选报修方式==",
            height: "150px",

        });
        $("#RepairedType").ComboBox({
            //  url: " ",
            data: [{ "key": "1", "value": "测试类别1" }, { "key": "2", "value": "测试类别2" }, { "key": "3", "value": "测试类别3" }],
            id: "key",
            text: "value",
            description: "==请选维修类别==",
            height: "150px"
        });
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            //description: "==请选择==",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("2017-07-10");
                        $("#EndTime").val("2017-07-16");
                        break;
                    case "2"://上周
                        $("#StartTime").val("2017-07-03");
                        $("#EndTime").val("2017-07-09");
                        break;
                    case "3"://本月
                        $("#StartTime").val("2017-07-01");
                        $("#EndTime").val("2017-07-31");
                        break;
                    case "4"://上月
                        $("#StartTime").val("2017-06-01");
                        $("#EndTime").val("2017-06-30");
                        break;
                    case "5"://本年
                        $("#StartTime").val("2017-01-01");
                        $("#EndTime").val("2017-12-31");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                $('#btn_Search').trigger("click");
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);




    }
    function GetTree1() {
        var item = {
            url: "../../PropertyManage/CS_DeviceRepair/GetStateTreeList",
            onnodeclick: function (item) {
                _State = item.value;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetTree2() {
        var item = {
            url: "../../ResourceManage/RS_Device/GetDeviceTypeTreeToJson",
            onnodeclick: function (item) {
                _DeviceId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree2").treeview(item);
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            OrganizeId: $("#OrganizeId").attr('data-value') == "" ? _organizeid : $("#OrganizeId").attr('data-value'),
            State: _State,
            DeviceId: _DeviceId,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val(),
            Code: $("#Code").val(),
            RepairWay: $("#RepairWay").attr('data-value'),
            RepairedType: $("#RepairedType").attr('data-value')
        };
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_DeviceRepair/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "单据编号", name: "Code", index: "Code", width: 150, align: "center", sortable: false },
                { label: "单据日期", name: "Date", index: "Date", width: 150, align: "center", sortable: false },
                { label: "设备编号", name: "DeviceCode", index: "DeviceId", width: 150, align: "center", sortable: false, hidden: true },
                { label: "设备名称", name: "DeviceName", index: "DeviceName", width: 100, align: "center", sortable: false, hidden: true },
                { label: "单据来源", name: "SourceType", index: "SourceType", width: 100, align: "center", sortable: false },
                {
                    label: "单据状态", name: "State", index: "State", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var Msg = "";
                        switch (cellvalue) {
                            case 1: Msg = "<span  class='label label-danger'>待处理</span>";
                                break;
                            case 2: Msg = "<span  class='label label-info'>派单中</span>";
                                break;
                            case 3: Msg = "<span  class='label label-info'>进行中</span>";
                                break;
                            case 4: Msg = "<span  class='label label-success'>已完成</span>";
                                break;
                            case 6: Msg = "<span  class='label label-warning'>未验收</span>";
                                break;
                            case 7: Msg = "<span  class='label label-success>已验收</span>";
                                break;
                            case 5: Msg = "<span  class='label label-inverse-learun'>不处理</span>";
                                break;
                            default: Msg = "---";
                                break;
                        }
                        return Msg;
                    }
                },
                { label: "报修方式", name: "BXWay", index: "RepairWay", width: 100, align: "center", sortable: false },
                { label: "报修时间", name: "BXDate", index: "RepairDate", width: 100, align: "center", sortable: false },
                { label: "报修人", name: "BXRName", index: "RepairMan", width: 200, align: "center", sortable: false },
                { label: "维修种类", name: "RepairedType", index: "RepairedType", width: 100, align: "center", sortable: false, hidden: true },
                { label: "报修内容", name: "BXContent", index: "RepairContent", width: 100, align: "center", sortable: false },
                { label: "备注", name: "Description", index: "Description", width: 100, align: "center", sortable: false }
            ],
            viewrecords: true,
            // rowNum: "all",
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                OrganizeId: $("#OrganizeId").attr('data-value') == "" ? _organizeid : $("#OrganizeId").attr('data-value'),
                State: _State,
                DeviceId: _DeviceId,
                StartTime: $("#StartTime").val(),
                EndTime: $("#EndTime").val(),
                Code: $("#Code").val(),
                RepairWay: $("#RepairWay").attr('data-value'),
                RepairedType: $("#RepairedType").attr('data-value')
            };
            $("#gridTable").jqGrid('setGridParam', {
                url: "../../ResourceManage/CS_DeviceRepair/GetPageList",
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#EndTime").val("");
            $("#StartTime").val("");
        })
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加维修',
            url: '/PropertyManage/CS_DeviceRepair/Form',
            width: "1100px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '修改维修',
                url: '/PropertyManage/CS_DeviceRepair/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "750px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })

        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: '/PropertyManage/CS_DeviceRepair/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style=" height:40%;  overflow-y: auto; ">
            <div id="itemTree1"></div>
        </div>
        <div class="west-Panel " style="height: 56.5%; overflow-y: auto;">
            <div id="itemTree2"></div>
        </div>
    </div>

    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td><div id="OrganizeId" type="selectTree" style="width:170px; margin-left:10px;" class="ui-select "></div></td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">报修方式</td>
                                                <td class="formValue">
                                                    <div id="RepairWay" type="select" class="ui-select"></div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">维修类别</td>
                                                <td class="formValue">
                                                    <div id="RepairedType" type="select" class="ui-select"></div>
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>

                        </tr>

                    </table>
                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>

            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>

